<!--Copyright (C) Kherty.  All rights reserved.-->
<ResourceDictionary
    x:Class="OpenLS.Chart.UI.PieSeriesResources"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:chart="http://schemas.Kherty.com/office/2007/chart"
    xmlns:chartui="clr-namespace:OpenLS.Chart.UI"
    xmlns:drawing2="clr-namespace:OpenLS.Drawing.UI;assembly=OpenLS.Drawing.UI"
    xmlns:Internals="clr-namespace:OpenLS.Chart.UI.Internals">
    
    <DataTemplate x:Key="pieItem">
        <Path 
                Style="{x:Static chartui:ShapedObjectResources.ShapedElementStyle}"
                Name="p" Internals:FormatHelper.HandlesChartCommands="True">
            <Path.Data>
                <MultiBinding Converter="{x:Static Internals:ChartConverters.NumericValueToArcDataConverter}">
                    <Binding/>
                    <Binding ElementName="outerGrid" Path="ActualWidth"/>
                    <Binding ElementName="outerGrid" Path="ActualHeight"/>
                    <Binding Path="Chart" RelativeSource="{RelativeSource Self}"/>
                    <Binding Path="Chart.Series[0]" RelativeSource="{RelativeSource Self}"/>
                </MultiBinding>
            </Path.Data>
            <chartui:ChartElement.DataPoint>
                <MultiBinding Converter="{x:Static Internals:ChartConverters.DataPointsAccessor}">
                    <Binding RelativeSource="{RelativeSource Self}" Path="(chartui:ChartElement.DataPointsObserver)"/>
                    <Binding Path="Index"/>
                    <Binding RelativeSource="{RelativeSource Self}" Path="(chartui:ChartElement.DataPointsObserver).Generation"/>
                </MultiBinding>
            </chartui:ChartElement.DataPoint>
            <drawing2:DrawingElement.ShapeProperties>
                <MultiBinding Converter="{x:Static Internals:ChartConverters.OrSkipNullConverter}">
                    <Binding Path="(chartui:ChartElement.DataPoint).ShapeProperties" RelativeSource="{RelativeSource  Self}" />
                    <Binding Path="(chartui:SeriesElement.Series).ShapeProperties" RelativeSource="{RelativeSource Self}" />
                </MultiBinding>
            </drawing2:DrawingElement.ShapeProperties>


          <!--  <Path.Fill>
                <MultiBinding Converter="{x:Static chartui:ChartConverters.ThemedElementToFillConverter}">
                    <Binding RelativeSource="{RelativeSource Self}" Path="(drawing2:DrawingElement.ColorScheme)"/>
                    <Binding Path="SeriesIndex" RelativeSource="{RelativeSource Self}"/>
                    <Binding Path="Index"/>
                    <Binding Path="(chartui:ChartElement.Chart).VaryColors" RelativeSource="{RelativeSource Self}"/>
                    <Binding Path="DataPoints" RelativeSource="{RelativeSource Self}"/>
                    <Binding Path="FillProperties" RelativeSource="{RelativeSource Self}"/>
                </MultiBinding>
            </Path.Fill> -->
            <Path.ContextMenu>
                <ContextMenu>
                    <MenuItem Command="{x:Static chartui:ChartCommands.UnformatDataSeries}"/>
                    <MenuItem Command="{x:Static chartui:ChartCommands.AddTitle}" />
                    <MenuItem Command="{x:Static chartui:ChartCommands.FormatDataSeries}"/>
                    <MenuItem Command="{x:Static chartui:ChartCommands.FormatDataPoint}"/>
                    <MenuItem Command="{x:Static chartui:ChartCommands.UnformatDataPoint}"/>
                </ContextMenu>
            </Path.ContextMenu>
        </Path>
        <DataTemplate.Triggers>
            <DataTrigger Binding="{Binding Path=(drawing2:DrawingElement.ShapeProperties).FillProperties, ElementName =p}" Value="{x:Null}">
                <Setter Property ="Fill" TargetName="p">
                    <Setter.Value>
                        <MultiBinding Converter="{x:Static Internals:ChartConverters.PatternConverter}">
                            <Binding RelativeSource="{RelativeSource Self}" Path="(chartui:ChartElement.Style)"/>
                            <Binding Path="Index"/>
                            <Binding RelativeSource="{RelativeSource Self}" Path="(drawing2:DrawingElement.Theme).ColorScheme"/>
                            <Binding Source="debug3"/>
                        </MultiBinding>
                    </Setter.Value>
                </Setter>
            </DataTrigger>
            <MultiDataTrigger>
                <MultiDataTrigger.Conditions>
                    <Condition Binding="{Binding Path=(drawing2:DrawingElement.ShapeProperties).FillProperties, ElementName =p}" Value="{x:Null}"/>
                    <Condition Binding="{Binding Path=(chartui:ChartElement.Chart).VaryColors, ElementName=p}" Value="False"/>
                </MultiDataTrigger.Conditions>
                <Setter Property ="Fill" TargetName="p">
                    <Setter.Value>
                        <MultiBinding Converter="{x:Static Internals:ChartConverters.PatternConverter}">
                            <Binding RelativeSource="{RelativeSource Self}" Path="(chartui:ChartElement.Style)"/>
                            <Binding Path="(chartui:SeriesElement.Series).Index" RelativeSource="{RelativeSource Self}"/>
                            <Binding Path="(drawing2:DrawingElement.Theme).ColorScheme" RelativeSource="{RelativeSource Self}" />
                            <Binding Source="debug5"/>
                        </MultiBinding>
                    </Setter.Value>
                </Setter>
            </MultiDataTrigger>
        </DataTemplate.Triggers>

    </DataTemplate>
    <DataTemplate DataType="{x:Type chart:PieSeries}">
        <ItemsControl ItemsSource="{Binding Values.Values}"
                      chartui:SeriesElement.Series="{Binding}"
                      ItemTemplate="{StaticResource pieItem}"
                      chartui:ChartElement.DataPoints="{Binding DataPoints}"
                      chartui:ChartElement.DataPointsObserver="{Binding DataPoints, Converter={x:Static Internals:ChartConverters.DataPointsObserverFactory}}"
                      >
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <Canvas/>
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
        </ItemsControl>
    </DataTemplate>
    
</ResourceDictionary>